/**
 * 
 */
package com.vector.ding.web.controller;

import java.util.List;
import java.util.Set;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.vector.ding.commons.util.front.BuiUtil;
import com.vector.ding.context.AuthContext;
import com.vector.ding.context.WebContext;
import com.vector.ding.dao.bean.MenuEntity;
import com.vector.ding.web.service.MenuService;
import com.vector.ding.web.service.UserService;

/**
 * @author vector
 *
 */
@Controller
@RequestMapping("/menumgr")
public class MenuController {
	
	@Autowired
	private MenuService menuService;
	@Autowired
	private UserService userService;

	@ResponseBody
	@RequestMapping(value="/getMenuData.do", method=RequestMethod.POST)
	public JSONArray getMenuData(String userId) {
		List<MenuEntity> menuEntities = WebContext.getMenuEntities();
		
		if (AuthContext.isAdmin())
			return BuiUtil.menuAdapter(menuEntities, null);
		Set<String> userMenuSet = userService.getUserMenuSet(userId);
		return BuiUtil.menuAdapter(menuEntities, userMenuSet);
	}
}
